/*
Name: addConversation
Author: IndeedPete
Purpose: Adds conversation from config to unit, i.e. adds action to start the conversation.
----------
Parameters:
_unit - OBJECT: Unit that the action should be attached to. - MyInterestingConversationPartner
_conversation - STRING: The config entry referring to the desired conversation. - "MyFirstConversation"
*/

_unit = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_conversation = [_this, 1, "", [""]] call BIS_fnc_param;
_condition = (missionConfigFile >> "Conversations" >> _conversation >> "condition");

if ((!isText _condition) OR {((getText _condition) == "") OR {call compile (getText _condition)}}) then {	
	_sentences = getArray(missionConfigFile >> "Conversations" >> _conversation >> "sentences");
	if (count _sentences == 0) exitWith {hint "IP_fnc_addConversation\nConversation " + str(_conversation) + " has no sentences!"};
	
	_arguments = (missionConfigFile >> "Conversations" >> _conversation >> "arguments");
	if ((isArray _arguments) && {count(getArray _arguments) > 0}) then {
		_arguments = getArray _arguments;
		for "_i" from 0 to ((count _arguments) - 1) do {
			_arguments set [_i, (call compile (_arguments select _i))];
		};
	} else {
		_arguments = [];
	};
	
	_firstSentence = _sentences select 0;
	_firstSentence = "'" + (format ([_firstSentence] + _arguments)) + "'";
	_id = _unit addAction [_firstSentence, {nul = [(_this select 1), (_this select 0), (_this select 3)] spawn IP_fnc_openConversation}, _conversation];
	_var = "IP_CONV_" + _conversation;
	_unit setVariable [_var, _id];
};